package cn.jdx.tools.md4img.tools;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class JdxToolsReadFile {
    public static String getContent(String filePath) {
        //[1].创建实例
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader(filePath));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //[2].开始读取
        String line = "";
        StringBuilder stringBuilder = new StringBuilder();
        try {
            while((line = bufferedReader.readLine())!= null){
                stringBuilder.append(line+"\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if (bufferedReader!=null){
                    bufferedReader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //[3].返回内容
        return stringBuilder.toString();
    }

}
